package com.qf.medicaldoctoradmin.healthRecord.service.impl;

import com.qf.common.entity.MedicalRecords;
import com.qf.common.entity.Monitor;
import com.qf.common.entity.Patient;
import com.qf.common.utils.UserUtils;
import com.qf.medicaldoctoradmin.healthMonitor.monitor.dao.MonitorDao;
import com.qf.medicaldoctoradmin.healthRecord.dao.HealthFileDao;
import com.qf.medicaldoctoradmin.healthRecord.dao.MedicalRecordsDao;
import com.qf.medicaldoctoradmin.healthRecord.dao.PatientDao;
import com.qf.medicaldoctoradmin.healthRecord.param.HealthParam;
import com.qf.medicaldoctoradmin.healthRecord.service.HealthFileService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * --- 业精于勤,荒于嬉 ---
 *
 * @author Song
 * @date 2024/11/16
 * @desc First
 */
@Service
public class HealthFileServiceImpl implements HealthFileService {

    @Resource
    private HealthFileDao healthFileDao;

    @Resource
    private MedicalRecordsDao medicalRecordsDao;

    @Resource
    private MonitorDao monitorDao;

    @Resource
    private PatientDao patientDao;


    // @Override
    // public void addFile(HealthParam param) {
    //
    //
    //     Patient patient = new Patient();
    //     patient.setUserId(UserUtils.getUid());
    //     patient.setBloodType(param.getBloodType());
    //     patient.setAllergies(param.getAllergies());
    //     patientDao.insert(patient);
    //
    //     Monitor monitor = new Monitor();
    //     monitor.setPatientId(UserUtils.getUid());
    //     monitor.setHeight(param.getHeight());
    //     monitor.setWeight(param.getWeight());
    //     monitorDao.insert(monitor);
    //
    //     MedicalRecords medicalRecords = new MedicalRecords();
    //     medicalRecords.setPastMedical(param.getPastMedical());
    //     medicalRecords.setConsultation(param.getConsultation());
    //     medicalRecords.setFamilyMedical(param.getFamilyMedical());
    //     medicalRecordsDao.insert(medicalRecords);
    //
    // }


    /**
     * 对健康档案健康信息做判断
     * @param param
     */
    @Override
    public void addFile(HealthParam param) {
        Patient patient = new Patient();
        patient.setUserId(UserUtils.getUid());

        // 判断过敏史
        if (param.getAllergies() != null && "有".equals(param.getAllergies())) {
            patient.setAllergies(param.getAllergies()); // 设置过敏信息
        } // 如果选择“无”，则不修改患者的过敏信息，或者可以选择设置为null

        // 如果需要修改患者信息，可以考虑在此处判断，比如 patientDao.update(patient) 之类的操作

        patientDao.insert(patient); // 插入患者信息

        Monitor monitor = new Monitor();
        monitor.setPatientId(UserUtils.getUid());

        monitorDao.insert(monitor); // 插入监测信息

        MedicalRecords medicalRecords = new MedicalRecords();

        // 判断既往病史
        if (param.getPastMedical() != null && "有".equals(param.getPastMedical())) {
            medicalRecords.setPastMedical(param.getPastMedical()); // 将既往病史设置为前端传来的数据
        } // 如果选择“无”，则不修改

        // 判断咨询记录
        if (param.getConsultation() != null && "有".equals(param.getConsultation())) {
            medicalRecords.setConsultation(param.getConsultation()); // 将咨询记录设置为前端传来的数据
        } // 如果选择“无”，则不修改

        // 判断家庭病史
        if (param.getFamilyMedical() != null && "有".equals(param.getFamilyMedical())) {
            medicalRecords.setFamilyMedical(param.getFamilyMedical()); // 将家庭病史设置为前端传来的数据
        } // 如果选择“无”，则不修改

        medicalRecordsDao.insert(medicalRecords); // 插入医疗记录信息
    }




}
